//
//  HSOrderCell.m
//  hsdyOrderSystem
//
//  Created by XunFengKJ on 2017/11/11.
//  Copyright © 2017年 赖国锋. All rights reserved.
//

#import "HSOrderCell.h"
#import "HSGuigeModel.h"
#import "HSFenliangModel.h"

@implementation HSOrderCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    self.readyUpBtn.layer.cornerRadius = 15;
    self.lookDetailBtn.layer.cornerRadius = 15;
    self.nameL.font = LGFBoldFont(16);
    self.moneyL.textColor = lColorRed;
    self.moneyL.font = LGFBoldFont(14);
}

-(void)setModel:(HSOrderModel *)model{
    _model = model;
    self.lookDetailBtn.tag = [model.outTradeNo integerValue];
    self.readyUpBtn.tag = [model.outTradeNo integerValue];
    self.orderNumLabel.text = [NSString stringWithFormat:@"下单用户:%@",model.wxUserPhone.length?model.wxUserPhone:@"暂无相关信息"];
    NSString *tableCount = [NSString stringWithFormat:@"%@",model.tableNumber];
    self.tableNumberL.text = [NSString stringWithFormat:@"桌位号:%@",tableCount.length?tableCount:@"暂无"];
    [self.pictureImageV sd_setImageWithURL:[NSURL URLWithString:@"xxxx"] placeholderImage:ImageNamed(@"morencaipin")];
    
    if (model.isShowComingtime) {
        self.orderTimeLabel.text =[NSString stringWithFormat:@"到店时间:%@",[NSString timeWithTimeIntervalString:model.reservationTime]];
    }else{
        self.orderTimeLabel.text =[NSString stringWithFormat:@"下单时间:%@",[NSString timeWithTimeIntervalString:model.createTime]];
    }
    
    
    self.readyUpBtn.hidden = !model.isHaveReadyUpBtn;//是否隐藏已上菜按钮
    
    if (model.foodsList.count == 0) return;
    HSOrderDetailModel *detailM = model.foodsList[0];
    [self.pictureImageV sd_setImageWithURL:[NSURL URLWithString:detailM.foodsImage] placeholderImage:ImageNamed(@"dishesDefaultPic")];
    self.nameL.text =detailM.name;
    NSString *floatTwo = [NSString floatTwoPointTurnString:[[NSString stringWithFormat:@"%@",detailM.price] floatValue]];
    self.moneyL.text = [NSString stringWithFormat:@"￥ %.2f",[floatTwo floatValue] ];
    self.shopCount.text = [NSString stringWithFormat:@"x %@",detailM.shopCount];
    
    NSString *floatTwoxx = [NSString floatTwoPointTurnString:[[NSString stringWithFormat:@"%@",model.totalPay] floatValue]];
    self.totalL.text =  [NSString stringWithFormat:@"共%@件商品，总计：%.2f",detailM.shopCount,[floatTwoxx floatValue]];
    
    NSString *guigeResultStr = @"";
    NSString *fengliangResultStr = @"";
    if (detailM.kinds.count > 0) {
        
        for (int i = 0; i < detailM.kinds.count; i ++) {
            HSGuigeModel *guigeM = detailM.kinds[i];
            //拼接
            guigeResultStr = [guigeResultStr stringByAppendingString:[NSString stringWithFormat:@"%@,",[NSArray matchingStringWithDataArr:guigeM.names]]];
        }
        if (guigeResultStr.length>1) {
            guigeResultStr = [guigeResultStr substringToIndex:guigeResultStr.length-1];
        }
        //规格
        self.standarL.text = [NSString stringWithFormat:@"规格：%@",guigeResultStr];
    }
    
   if (detailM.prices.count > 0) {
       for (int i = 0; i < detailM.prices.count; i ++) {
           HSFenliangModel *fengliangM = detailM.prices[i];
           //拼接
           fengliangResultStr = [fengliangResultStr stringByAppendingString:[NSString stringWithFormat:@"%@,",fengliangM.name]];
       }
       if (fengliangResultStr.length>1) {
           fengliangResultStr = [fengliangResultStr substringToIndex:fengliangResultStr.length-1];
       }
       //份量
       self.fengliangL.text =[NSString stringWithFormat:@"份量：%@",fengliangResultStr];
   }
    
}

//已上菜
- (IBAction)readyUpBtnClick:(UIButton*)sender {
    if (self.CompleteBtnBlock){
        self.CompleteBtnBlock(sender.tag);
    }
}

//查看详情
- (IBAction)lookDetailBtnClick:(UIButton*)sender {
    if (self.DetailBtnBlock){
        self.DetailBtnBlock(sender.tag);
    }
}

////除100区两位小数
//-(float)roundFloat:(float)price{
//    return  round(price * 100) / 10000;
//}
@end
